package com.oa.cms.converter;

import com.oa.cms.converter.base.BaseConvert;
import com.oa.cms.domain.dto.CmsVersionDto;
import com.oa.cms.domain.entity.CmsVersion;
import org.springframework.stereotype.Service;

/**
 * Created by gold-jx on 2017/12/6.
 */
@Service
public class CmsVersionConverter implements BaseConvert<CmsVersion,CmsVersionDto> {


    @Override
    public  CmsVersionDto convertToDto(CmsVersion cmsVersion) {
        if (cmsVersion == null) {
            return null;
        }
        return copyToDto(cmsVersion);
    }

    @Override
    public  CmsVersion convertToEntity(CmsVersionDto cmsVersionDto) {
        if (cmsVersionDto == null) {
            return null;
        }
        return copyToEntity(cmsVersionDto);
    }


    /**
     * entity转换为dto
     * @param cv
     * @return
     */
    private static CmsVersionDto copyToDto(CmsVersion cv){
        CmsVersionDto cvd=new CmsVersionDto();
        cvd.setId(cv.getId());
        cvd.setVersionType(cv.getVersionType());
        cvd.setVersion(cv.getVersion());
        cvd.setDownPath(cv.getDownPath());
        cvd.setCreateTime(cv.getCreateTime());
        cvd.setStatus(cv.getStatus());
        cvd.setTips(cv.getTips());
        return cvd;
    }

    /**
     * dto转换为entity
     * @param cvd
     * @return
     */
    private static CmsVersion copyToEntity(CmsVersionDto cvd){
        CmsVersion cv=new CmsVersion();
        cv.setId(cvd.getId());
        cv.setVersionType(cvd.getVersionType());
        cv.setVersion(cvd.getVersion());
        cv.setDownPath(cvd.getDownPath());
        cv.setCreateTime(cvd.getCreateTime());
        cv.setStatus(cvd.getStatus());
        cv.setTips(cvd.getTips());
        return cv;
    }

}
